{
    auto_https disable_redirects
}

{$DOMAIN_NAMES} {
	root * /srv/webroot
    route {
        # Add trailing slash for directory requests
        @canonicalPath {
            file {path}/index.php
            not path */
        }
        redir @canonicalPath {http.request.orig_uri.path}/ 308

        # If the requested file does not exist, try index files
        @indexFiles file {
            try_files {path} {path}/index.php =404
            split_path .php
        }
        rewrite @indexFiles {file_match.relative}

        # Proxy PHP files to the FastCGI responder
        @phpFiles path *.php
        reverse_proxy @phpFiles primmarket-php:9000 {
            transport fastcgi {
                split .php
            }
        }
    }
    file_server

    handle_errors {
        @custom_err file /err-{err.status_code}.html /err.html
        handle @custom_err {
            rewrite * {file_match.relative}
            file_server
        }
        respond "{err.status_code} {err.status_text}"
    }
}
